package ru.sstu.renju.ui.renderers;

import java.awt.Graphics;

import ru.sstu.renju.core.CellType;
import ru.sstu.renju.core.Row;

/**
 * <code>GameRenderer</code> class and its subclasses are responsible for
 * rendering of game field.
 *
 * @author denis_murashev
 * @since Renju 1.0
 */
public abstract class GameRenderer {

	private final String name;
	private final int cellSize;

	/**
	 * @param name     renderer name
	 * @param cellSize cell size
	 */
	public GameRenderer(String name, int cellSize) {
		this.name = name;
		this.cellSize = cellSize;
	}

	@Override
	public String toString() {
		return name;
	}

	/**
	 * Painting game field.
	 *
	 * @param g graphics
	 */
	public abstract void paintField(Graphics g);

	/**
	 * Painting cell.
	 *
	 * @param g    graphics
	 * @param i    column index
	 * @param j    row index
	 * @param type cell type
	 */
	public void paintCell(Graphics g, int i, int j, CellType type) {
		if (type == CellType.BLACK) {
			paintBlack(g, i, j);
		} else if (type == CellType.WHITE) {
			paintWhite(g, i, j);
		}
	}

	/**
	 * Painting winning row.
	 *
	 * @param g   graphics
	 * @param row row
	 */
	public abstract void paintRow(Graphics g, Row row);

	/**
	 * @return the cellSize
	 */
	protected int getCellSize() {
		return cellSize;
	}

	/**
	 * Painting Black Stone (or Cross).
	 *
	 * @param g graphics
	 * @param i column index
	 * @param j row index
	 */
	protected abstract void paintBlack(Graphics g, int i, int j);

	/**
	 * Painting White Stone (or Nought).
	 *
	 * @param g graphics
	 * @param i column index
	 * @param j row index
	 */
	protected abstract void paintWhite(Graphics g, int i, int j);
}
